import { Component, OnInit } from "@angular/core";
import { CommentListService } from "./comment-list.service";
import { ActivatedRoute } from "@angular/router";

@Component({
  selector: "app-comment-list",
  templateUrl: "./comment-list.component.html",
  styleUrls: ["./comment-list.component.scss"]
})
export class CommentListComponent implements OnInit {
  public comments: Array<any> = [];
  constructor(
    public commentService: CommentListService,
    public activatedRoute: ActivatedRoute
  ) {}

  ngOnInit(): void {
    this.activatedRoute.params.subscribe(params =>
      this.getCommentList(params["postId"])
    );
  }

  public getCommentList(postId: number) {
    this.commentService.getCommentList(postId).subscribe(
      res => {
        this.comments = res["items"];
      },
      err => {
        console.log(err);
      }
    );
  }
}
